package com.mdd.admin.controller.jiaz.engineer;

import com.mdd.admin.service.jiaz.IEngineerLevelService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validate.engineer.EngineerLevelCreateValidate;
import com.mdd.common.validate.engineer.EngineerLevelListedVo;
import com.mdd.common.validate.engineer.EngineerLevelUpdateValidate;
import com.mdd.common.validator.annotation.IDMust;
import com.mdd.common.vo.engineer.EngineerLevelDetailVo;
import com.mdd.common.vo.engineer.EngineerLevelSelectListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("api/engineer/level")
@Api(tags = "师傅等级管理")
public class EngineerLevelController {

    @Resource
    IEngineerLevelService engineerLevelService;

    @GetMapping("/list")
    @ApiOperation("等级列表")
    public AjaxResult<PageResult<EngineerLevelListedVo>> list(@Validated PageValidate pageValidate) {
        PageResult<EngineerLevelListedVo> list = engineerLevelService.list(pageValidate);
        return AjaxResult.success(list);
    }

    @PostMapping("/add")
    @ApiOperation("等级新增")
    public AjaxResult<Object> add(@Validated @RequestBody EngineerLevelCreateValidate createValidate) {
        engineerLevelService.add(createValidate);
        return AjaxResult.success();
    }

    @PostMapping("/edit")
    @ApiOperation("等级编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody EngineerLevelUpdateValidate updateValidate) {
        engineerLevelService.edit(updateValidate);
        return AjaxResult.success();
    }

    @GetMapping("/detail")
    @ApiOperation("等级详情")
    public AjaxResult<EngineerLevelDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        EngineerLevelDetailVo vo = engineerLevelService.detail(id);
        return AjaxResult.success(vo);
    }

    @PostMapping("/del")
    @ApiOperation("等级删除")
    public AjaxResult<Object> delete(@Validated @RequestBody IdValidate idValidate) {
        engineerLevelService.delete(idValidate.getId());
        return AjaxResult.success();
    }

    @GetMapping("/selectList")
    @ApiOperation("等级列表")
    public AjaxResult<Object> selectList() {
        List<EngineerLevelSelectListVo> list = engineerLevelService.selectList();
        return AjaxResult.success(list);
    }

}
